/*     */ package com.newcrm.db;
/*     */ 
/*     */ import com.newcrm.exception.DBException;
/*     */ import java.sql.Connection;
/*     */ import java.sql.SQLException;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import org.apache.commons.dbutils.DbUtils;
/*     */ import org.apache.commons.dbutils.MyMapHandler;
/*     */ import org.apache.commons.dbutils.MyMapListHandler;
/*     */ import org.apache.commons.dbutils.QueryRunner;
/*     */ import org.apache.commons.dbutils.handlers.MapListHandler;
/*     */ import org.apache.log4j.Logger;
/*     */ 
/*     */ public class UserVOIPManager
/*     */ {
/*  26 */   private static Logger logger = Logger.getLogger(UserVOIPManager.class
/*  27 */     .getName());
/*     */ 
/*     */   public int add(String id, String userName, String userPwd, String type, int companyId)
/*     */     throws SQLException, DBException
/*     */   {
/*  41 */     Connection conn = ConnectionManager.getInstance().getConnection();
/*  42 */     if (conn == null) {
/*  43 */       throw new DBException();
/*     */     }
/*  45 */     QueryRunner runner = new QueryRunner();
/*     */     try
/*     */     {
/*  48 */       return runner.update(conn, "INSERT INTO T_User_VOIP (UserId,UserName,UserPwd,VOIPType,CompanyId,CreateDate,UpdateDate) VALUES (?,?,?,?,?,NOW(),NOW())", new Object[] { id, userName, 
/*  49 */         userPwd, type, Integer.valueOf(companyId) });
/*     */     } finally {
/*     */       try {
/*  52 */         DbUtils.close(conn);
/*     */       } catch (SQLException e) {
/*  54 */         logger.warn("close conn failed", e);
/*     */       }
/*     */     }
/*     */   }
/*     */ 
/*     */   public int update(String id, String userName, String userPwd, String type)
/*     */     throws SQLException, DBException
/*     */   {
/*  71 */     Connection conn = ConnectionManager.getInstance().getConnection();
/*  72 */     if (conn == null) {
/*  73 */       throw new DBException();
/*     */     }
/*  75 */     QueryRunner runner = new QueryRunner();
/*     */     try
/*     */     {
/*  78 */       return runner.update(conn, "UPDATE T_User_VOIP SET UserName = ?, UserPwd = ?, VOIPType = ?, UpdateDate = NOW() WHERE UserId = ?", new Object[] { userName, 
/*  79 */         userPwd, type, id });
/*     */     } finally {
/*     */       try {
/*  82 */         DbUtils.close(conn);
/*     */       } catch (SQLException e) {
/*  84 */         logger.warn("close conn failed", e);
/*     */       }
/*     */     }
/*     */   }
/*     */ 
/*     */   public int clear(int companyId, String userId)
/*     */     throws SQLException, DBException
/*     */   {
/*  99 */     Connection conn = ConnectionManager.getInstance().getConnection();
/* 100 */     if (conn == null) {
/* 101 */       throw new DBException();
/*     */     }
/* 103 */     QueryRunner runner = new QueryRunner();
/*     */     try
/*     */     {
/* 106 */       return runner.update(conn, "DELETE FROM T_User_VOIP WHERE CompanyId = ? AND UserId = ?", new Object[] { Integer.valueOf(companyId), 
/* 107 */         userId });
/*     */     } finally {
/*     */       try {
/* 110 */         DbUtils.close(conn);
/*     */       } catch (SQLException e) {
/* 112 */         logger.warn("close conn failed", e);
/*     */       }
/*     */     }
/*     */   }
/*     */ 
/*     */   public Map<String, Object> getUserVOIPSetting(String userId)
/*     */     throws DBException, SQLException
/*     */   {
/* 127 */     Connection conn = ConnectionManager.getInstance().getConnection();
/* 128 */     if (conn == null) {
/* 129 */       throw new DBException();
/*     */     }
/*     */ 
/* 132 */     QueryRunner runner = new QueryRunner();
/*     */     try {
/* 134 */       return (Map)runner.query(conn, "SELECT * FROM T_User_VOIP WHERE UserId = ?", 
/* 135 */         new MyMapHandler(), new Object[] { userId });
/*     */     } finally {
/*     */       try {
/* 138 */         DbUtils.close(conn);
/*     */       } catch (SQLException e) {
/* 140 */         logger.warn("close conn failed", e);
/*     */       }
/*     */     }
/*     */   }
/*     */ 
/*     */   public Map<String, Object> getUserAdminVOIPSetting()
/*     */     throws DBException, SQLException
/*     */   {
/* 154 */     Connection conn = ConnectionManager.getInstance().getConnection();
/* 155 */     if (conn == null) {
/* 156 */       throw new DBException();
/*     */     }
/*     */ 
/* 159 */     QueryRunner runner = new QueryRunner();
/*     */     try {
/* 161 */       return (Map)runner.query(conn, "SELECT * FROM T_User_VOIP WHERE UserName like '8000%'", 
/* 162 */         new MyMapHandler());
/*     */     } finally {
/*     */       try {
/* 165 */         DbUtils.close(conn);
/*     */       } catch (SQLException e) {
/* 167 */         logger.warn("close conn failed", e);
/*     */       }
/*     */     }
/*     */   }
/*     */ 
/*     */   public List<Map<String, Object>> getUsersVOIPSeatInfo(int companyId)
/*     */   {
/* 180 */     Connection conn = ConnectionManager.getInstance().getConnection();
/* 181 */     if (conn == null) {
/* 182 */       return null;
/*     */     }
/* 184 */     QueryRunner runner = new QueryRunner();
/*     */     try {
/* 186 */       return (List)runner.query(conn, "SELECT A.UserId, A.UserName, A.UserPwd, A.VOIPType, B.GroupId, B.Name FROM T_User_VOIP AS A INNER JOIN T_User_Info AS B ON A.UserId = B.UserId WHERE A.CompanyId = ?", 
/* 187 */         new MapListHandler(), new Object[] { Integer.valueOf(companyId) });
/*     */     } catch (SQLException e) {
/* 189 */       logger.warn("get UsersVOIP seats Information failed", e);
/*     */     } finally {
/*     */       try {
/* 192 */         DbUtils.close(conn);
/*     */       } catch (SQLException e) {
/* 194 */         logger.warn("close conn failed", e);
/*     */       }
/*     */     }
/* 197 */     return null;
/*     */   }
/*     */ 
/*     */   public List<Map<String, Object>> getUsersVOIPName(Connection conn, int companyId)
/*     */   {
/* 209 */     if (conn == null) {
/* 210 */       return null;
/*     */     }
/* 212 */     QueryRunner runner = new QueryRunner();
/*     */     try {
/* 214 */       return (List)runner.query(conn, "SELECT UserId, UserName FROM T_User_VOIP WHERE CompanyId = ?", 
/* 215 */         new MyMapListHandler(), new Object[] { Integer.valueOf(companyId) });
/*     */     } catch (SQLException e) {
/* 217 */       logger.warn("get UsersVOIPName list failed", e);
/*     */     }
/* 219 */     return null;
/*     */   }
/*     */ 
/*     */   public List<Map<String, Object>> getUsersVOIPInfos(int companyId)
/*     */   {
/* 229 */     Connection conn = ConnectionManager.getInstance().getConnection();
/* 230 */     if (conn == null) {
/* 231 */       return null;
/*     */     }
/* 233 */     QueryRunner runner = new QueryRunner();
/*     */     try {
/* 235 */       return (List)runner.query(conn, "SELECT A.UserName, B.GroupId, B.Name, C.GroupName FROM T_User_VOIP AS A INNER JOIN T_User_Info AS B ON A.UserId = B.UserId LEFT JOIN T_Company_Group_Info AS C ON B.GroupId = C.GroupId WHERE A.CompanyId = ?", 
/* 236 */         new MapListHandler(), new Object[] { Integer.valueOf(companyId) });
/*     */     } catch (SQLException e) {
/* 238 */       logger.warn("get UsersVOIP list failed", e);
/*     */     } finally {
/*     */       try {
/* 241 */         DbUtils.close(conn);
/*     */       } catch (SQLException e) {
/* 243 */         logger.warn("close conn failed", e);
/*     */       }
/*     */     }
/* 246 */     return null;
/*     */   }
/*     */ }

/* Location:           C:\E\referenceProject\CRM参考\qikebao\WEB-INF\lib\qikebao.jar
 * Qualified Name:     com.newcrm.db.UserVOIPManager
 * JD-Core Version:    0.6.1
 */